package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.bo.CarerBo;
import com.java2207.group1.bo.StaffBo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.CarerMapper;
import com.java2207.group1.pojo.Carer;
import com.java2207.group1.service.CarerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author HLJ
 * @Date 2022/7/26 07
 */
@Service("carerService")
public class CarerServiceImpl implements CarerService {

    @Autowired
    private CarerMapper carerMapper;

    @Override
    public LayuiPageVo<Carer> carerPageDate(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");

        PageHelper.startPage(page,limit);

        List<Carer>list = carerMapper.carerPageDate(params);

        PageInfo<Carer> carerPageInfo = new PageInfo<>(list);

        LayuiPageVo<Carer> vo = new LayuiPageVo<>();

        vo.setCode(0);
        vo.setMsg("护工分页数据");
        vo.setCount(carerPageInfo.getTotal()); // 总记录数
        vo.setData(carerPageInfo.getList());

        return vo;
    }

    @Override
    public int addCarer(Carer carer) {
        return carerMapper.addCarer(carer);
    }

    @Override
    public int deleteCarer(Carer carer) {
        return carerMapper.deleteCarer(carer);
    }

    @Override
    public int updateCarer(Carer carer) {
        return carerMapper.updateCarer(carer);
    }

    @Override
    public int removeCarer(String ids) {
        String [] arrId = ids.split(",");

        return carerMapper.removeCarer(arrId);
    }

    @Override
    public List<CarerBo> carerExcelData(Map<String, Object> params) {
        List<Carer> list = carerMapper.carerPageDate(params);
        List<CarerBo> carerBos = list.stream().map((sta) -> {
            CarerBo carerBo = new CarerBo();
            carerBo.setId(sta.getId());
            carerBo.setEmpId(sta.getEmpId());
            carerBo.setName(sta.getName());
            carerBo.setDormId(sta.getDormId());
            carerBo.setPic(sta.getPic());
            return carerBo;
        }).collect(Collectors.toList());

        return carerBos;
    }

    //  // 直接拿 宿舍表的宿舍号 和 员工档案表的护工照片到 护工档案表中
    @Override
    public void carerUpdateDid() {
        carerMapper.carerUpdateDid();
    }

    @Override
    public void carerUpdatepic() {
        carerMapper.carerUpdatepic();
    }




}
